# Figure 5: Voting in Single and Multiple Propositions


# 1. Load Packages ----

library(tidyverse)

# 2. Read in Data ----

load(file = "df_voxit_individual_props.RData")

# 3. Prepare Data ----
# Generate Quantiles
utility_quantiles <- quantile(voxit_propositions$utility_optc,c(0.33,0.66))

# Generate other variables
voxit_df <- voxit_propositions %>% 
  ungroup %>%
  select(turnout,empty_ballot,utility_optc,propositions) %>%
  mutate(voted=ifelse(turnout==1 & empty_ballot==0,1,0),
         single_prop=ifelse(propositions==1,"Single proposition voting day",
                            "Multiple proposition voting day"),
         utility=cut(utility_optc,breaks=c(0,quantile(voxit_propositions$utility_optc,
                                                      probs=c(1:4)/4))),
         utility_fct=factor(x = utility,
                            labels = c("Quartile 1","Quartile 2","Quartile 3"," Quartile 4"),
                            ordered = T)) %>%
  group_by(utility_fct,single_prop) %>%
  summarize(voted_av=mean(voted,na.rm=T)) %>%
  filter(!is.na(utility_fct))

# 4. Create Graph ----
ggplot(data=voxit_df ,
       mapping=aes(x=utility_fct,y=voted_av,
                   shape=single_prop,
                   color=single_prop)) + 
  geom_point(size=2) +
  theme_bw() +
  ylab("Share of individuals who participate") +
  xlab("Proposition net benefit") +
  scale_shape_discrete(name = "")  + 
  scale_color_brewer(palette="Set1",name = "")+
  theme(legend.position="bottom") 

# 5. Save Graph ----
ggsave(filename = "Figure5.pdf", width = 6.4, height = 4.8)